using System;

using Microsoft.SPOT;

using mfRCF.Core;
using mfRCF.Core.Extensions;

using mfXmlSerializer;

using mfLogger;

using OST.Shared.SharedTypes;
using OST.Persistence;
using OST.Shared;

namespace OST.Commands
{
    using Extensions;

    /// <summary>
    /// applies the actual configuration
    /// </summary>
    public class ConfigurationApplyGETCommand : mfRcfCommand
    {
        #region CTOR

        public ConfigurationApplyGETCommand(string httpPath)
            : base(httpPath, new mfGETMethod())
        {
        }

        #endregion

        #region Properties

        /// <summary>
        /// wrapper-property 4 logging
        /// </summary>
        private ILoggerAppender Logger
        {
            get
            {
                return mfLogger.mfLogger.Instance;
            }
        }

        #endregion

        #region mfRcfCommand
        public override void ExecuteCommand(mfIHttpContext httpContext)
        {
            try
            {
                if (!ConfigurationProvider.Instance.HasConfig)
                    throw new OSTException("no config loaded");

                //TODO: test /configuration/apply
                throw new OSTException("config-rest-apply not yet tested well, please restart the controller");

                //ConfigurationProvider.Instance.ConfigInstance.Validate();
                //ConfigurationProvider.Instance.Apply();

                //this.WriteHttpResponseOK(httpContext, "config applied");
            }
            catch (Exception ex)
            {
                this.WriteHttpResponseError(httpContext, ex);
            }
        }
        #endregion
    }
}
